package com.siwei.mes.entity.experiment.coarseAggregate;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import com.siwei.mes.common.util.NullUtils;
import com.siwei.mes.entity.experiment.fineAggregate.FineAggregateJmmd;
import com.siwei.mes.entity.laboratory.coarseAggregate.DataCoarseAggregateHnl;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @Description: 粗骨料-含泥量
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/02/25 21:29
 */
@Data
@Accessors(chain = true)
public class CoarseAggregateHnl {
    @ApiModelProperty(value = "平均值")//1
    private String hnlpjz = "";
    @ApiModelProperty(value = "单项结论")//1
    private String dxjl = "";
    @ApiModelProperty(value = "检测日期")
    private String jcrq = "";
    @ApiModelProperty(value = "含泥量信息")
    private List<CoarseAggregateHnl.HnlInfo> hnlInfo = Collections.singletonList(new CoarseAggregateHnl.HnlInfo());

    @Data
    @Accessors(chain = true)
    @ApiModel("含泥量信息")
    public static class HnlInfo {
        @ApiModelProperty(value = "烘前试样质量")
        private String hqsyzl = "";
        @ApiModelProperty(value = "烘后试样质量")
        private String hhsyzl = "";
        @ApiModelProperty(value = "含泥量")
        private String hnl = "";
    }

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        CoarseAggregateHnl entity = new CoarseAggregateHnl();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, CoarseAggregateHnl.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, CoarseAggregateHnl.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        CoarseAggregateHnl entity = JsonUtils.getObject(objJson, CoarseAggregateHnl.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        if (StringUtils.isBlank(entity.getHnlpjz()) || "null".equals(entity.getHnlpjz())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        /*if (StringUtils.isBlank(entity.getDxjl()) || "null".equals(entity.getDxjl())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }*/
        return null;
    }

    public static void setValue(CoarseAggregateHnl entity, DataCoarseAggregateHnl data) {
        List<CoarseAggregateHnl.HnlInfo> hnlInfoList = entity.getHnlInfo();
        HnlInfo hnlInfoOne = hnlInfoList.get(0);
        hnlInfoOne.setHqsyzl(NullUtils.ifNull(data.getS1()));
        hnlInfoOne.setHhsyzl(NullUtils.ifNull(data.getS2()));
        hnlInfoOne.setHnl(NullUtils.ifNull(data.getS3()));
        HnlInfo hnlInfoTwo = hnlInfoList.get(1);
        hnlInfoTwo.setHqsyzl(NullUtils.ifNull(data.getS4()));
        hnlInfoTwo.setHhsyzl(NullUtils.ifNull(data.getS5()));
        hnlInfoTwo.setHnl(NullUtils.ifNull(data.getS6()));
        if(data.getS7()!=null){
            entity.setHnlpjz(NullUtils.ifNull(data.getS7()));
        }
    }
}
